﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_size_nulable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicConfigId",
                table: "MainStdFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdTableDict_MainStdApiConfig_StdApiConfigId",
                table: "MainStdTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdViewContainerDict_MainStdApiConfig_StdApiConfigId",
                table: "MainStdViewContainerDict");

            migrationBuilder.DropTable(
                name: "MainStdApiConfig");

            migrationBuilder.RenameColumn(
                name: "TopicConfigId",
                table: "MainStdFormDict",
                newName: "TopicDictId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdFormDict_TopicConfigId",
                table: "MainStdFormDict",
                newName: "IX_MainStdFormDict_TopicDictId");

            migrationBuilder.AlterColumn<string>(
                name: "Size",
                table: "MainStdViewContainerDict",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.AlterColumn<string>(
                name: "Layout",
                table: "MainStdViewContainerDict",
                type: "text",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.AddColumn<DateTime>(
                name: "CreationTime",
                table: "MainStdFormDict",
                type: "timestamp with time zone",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<Guid>(
                name: "CreatorId",
                table: "MainStdFormDict",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastModificationTime",
                table: "MainStdFormDict",
                type: "timestamp with time zone",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "LastModifierId",
                table: "MainStdFormDict",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Layout",
                table: "MainStdFormDict",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<string>(
                name: "Mode",
                table: "MainStdFormDict",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "MainStdApiDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ApiDictName = table.Column<string>(type: "text", nullable: false),
                    TopicDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    InfNo = table.Column<string>(type: "text", nullable: false),
                    SignType = table.Column<string>(type: "text", nullable: true),
                    InfVerno = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdApiDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdApiDict_MainTopicDict_TopicDictId",
                        column: x => x.TopicDictId,
                        principalTable: "MainTopicDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdApiDict_TopicDictId",
                table: "MainStdApiDict",
                column: "TopicDictId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicDictId",
                table: "MainStdFormDict",
                column: "TopicDictId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdTableDict_MainStdApiDict_StdApiConfigId",
                table: "MainStdTableDict",
                column: "StdApiConfigId",
                principalTable: "MainStdApiDict",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdViewContainerDict_MainStdApiDict_StdApiConfigId",
                table: "MainStdViewContainerDict",
                column: "StdApiConfigId",
                principalTable: "MainStdApiDict",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicDictId",
                table: "MainStdFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdTableDict_MainStdApiDict_StdApiConfigId",
                table: "MainStdTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStdViewContainerDict_MainStdApiDict_StdApiConfigId",
                table: "MainStdViewContainerDict");

            migrationBuilder.DropTable(
                name: "MainStdApiDict");

            migrationBuilder.DropColumn(
                name: "CreationTime",
                table: "MainStdFormDict");

            migrationBuilder.DropColumn(
                name: "CreatorId",
                table: "MainStdFormDict");

            migrationBuilder.DropColumn(
                name: "LastModificationTime",
                table: "MainStdFormDict");

            migrationBuilder.DropColumn(
                name: "LastModifierId",
                table: "MainStdFormDict");

            migrationBuilder.DropColumn(
                name: "Layout",
                table: "MainStdFormDict");

            migrationBuilder.DropColumn(
                name: "Mode",
                table: "MainStdFormDict");

            migrationBuilder.RenameColumn(
                name: "TopicDictId",
                table: "MainStdFormDict",
                newName: "TopicConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainStdFormDict_TopicDictId",
                table: "MainStdFormDict",
                newName: "IX_MainStdFormDict_TopicConfigId");

            migrationBuilder.AlterColumn<string>(
                name: "Size",
                table: "MainStdViewContainerDict",
                type: "text",
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Layout",
                table: "MainStdViewContainerDict",
                type: "text",
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "text",
                oldNullable: true);

            migrationBuilder.CreateTable(
                name: "MainStdApiConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    OpenApiConfigCodg = table.Column<string>(type: "text", nullable: false),
                    OpenApiConfigName = table.Column<string>(type: "text", nullable: false),
                    SrtNo = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdApiConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdApiConfig_MainTopicDict_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdApiConfig_TopicConfigId",
                table: "MainStdApiConfig",
                column: "TopicConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdFormDict_MainTopicDict_TopicConfigId",
                table: "MainStdFormDict",
                column: "TopicConfigId",
                principalTable: "MainTopicDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdTableDict_MainStdApiConfig_StdApiConfigId",
                table: "MainStdTableDict",
                column: "StdApiConfigId",
                principalTable: "MainStdApiConfig",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdViewContainerDict_MainStdApiConfig_StdApiConfigId",
                table: "MainStdViewContainerDict",
                column: "StdApiConfigId",
                principalTable: "MainStdApiConfig",
                principalColumn: "Id");
        }
    }
}
